<template>
  <view class="order-info">
    <OrderInfo v-if="initFinish" :form-data="formData" :submit-show="formData.workStatus < 2" @submit="submit" />
  </view>
</template>

<script>
  import OrderInfo from '../../../../components/order-info/OrderInfo';
  import {
    getMeasureOrderDetail,
  } from '../../../../api/device/device.js';
  
  export default {
    name: 'orderInfo',
    components: { OrderInfo },
    data() {
      return {
        workId: '',
        formData: {},
        initFinish: false,
      };
    },
    methods: {
      async getData() {
        const res = await getMeasureOrderDetail({
          workId: this.workId,
        }).catch(() => {
        });
        if (res.code === 200) {
          const workerList = [];
          if (res.data.workEnginner1Name) {
            workerList.push(res.data.workEnginner1Name);
          }
          if (res.data.workEnginner2) {
            workerList.push(res.data.workEnginner2);
          }
          if (res.data.workEnginner3) {
            workerList.push(res.data.workEnginner3);
          }
          this.formData = { ...res.data, worker: workerList.join(',') };
        }
        this.initFinish = true;
      },
      submit() {
        uni.navigateTo({
          url: `/pages/order/order-detail/measure/orderDetail?workId=${this.workId}`,
        });
      },
    },
    onShow() {
      const pageList = getCurrentPages();
      const param = pageList[ pageList.length - 1 ].options || {};
      this.workId = param.workId;
      this.getData();
    },
  };
</script>

<style lang="scss" scoped>
  .order-info {
    &, * {
      box-sizing: border-box;
    }
  }
  
  page {
    background-color: white;
  }

</style>
